using ARC.API.ExternalInterface.CurrencyInterface;
using Micro.Core.FrameWork.Cache;
using Micro.Core.FrameWork.Cache.Redis;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using Micro.SMSGatWay.Core.Extensions;
using Micro.SMSGatWay.Core;
using ARC.API.ExternalInterface.CurrencyService;
using Micro.SMSGatWay.Core.Repository.SmsSendHistory;
using Micro.SMSGatWay.Core.Repository.SmsSignInfo;
using Micro.SMSGatWay.Core.Repository.SmsTemplateInfo;
using Micro.SMSGatWay.Core.Service;

namespace Micro.SMSGatWay.API
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient<SmsAppConfig>();

            services.AddScoped<ISmsSignInfoRepository, SmsSignInfoRepository>();
            services.AddScoped<ISmsTemplateInfoRepository, SmsTemplateInfoRepository>();
            services.AddScoped<ISmsSendHistoryRepository, SmsSendHistoryRepository>();


            services.AddScoped<ICurrencyInterfaceSdkSmsClient, CurrencyInterfaceSdkSmsClient>();
            services.AddSingleton<ICache>(new RedisCache(Configuration));
            services.AddScoped<ISmsApiService, SmsApiService>();
            services.AddEntityFrameWorkCore(Configuration["DbConnectString"], Configuration["DbConnectVersion"]);
            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "Micro.SMSGatWay.API", Version = "v1" });
            });
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Micro.SMSGatWay.API v1"));
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }

    public class aa
    {
        public string Type { get; set; }
    }
}
